﻿using Gnivc.CarDealership.Api.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Gnivc.CarDealership.Api.Infrastructure.Persistence.PersistenceConstants;

namespace Gnivc.CarDealership.Api.Infrastructure.Persistence.Configurations;

public class ReservationConfiguration : IEntityTypeConfiguration<Reservation>
{
    public void Configure(EntityTypeBuilder<Reservation> builder)
    {
        builder.ToTable(TableNames.Reservations, SchemaNames.Retail)
            .HasKey(x => x.Id);

        builder.HasOne(x => x.Vehicle)
            .WithMany(x => x.Reservations)
            .HasForeignKey(x => x.VehicleId);

        builder.HasOne(x => x.User)
            .WithMany(x => x.Reservations)
            .HasForeignKey(x => x.UserId);
    }
}
